package com.fanghuaiming.seata.order.controller;

import com.fanghuaiming.seata.order.dao.model.OrderInfo;
import com.fanghuaiming.seata.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/****
 * @description: 订单服务接口
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2020/11/27 下午2:00
 *
 */
@RestController("order")
@RequestMapping("/order")
@Slf4j
public class OrderController {

    /**
     * 订单服务
     */
    @Autowired
    private OrderService orderService;

    /**
     * @Description: 下订单接口
     *
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/27 下午2:25
     * @version:1.0.0
     */
    @PostMapping(value = "/placeOrder")
    public String placeOrder(@RequestBody OrderInfo orderInfo) {
        try {
            log.info("=================开始请求-订单微服务-placeOrder下订单接口Controller接口=================");
            orderService.placeOrder(orderInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return "接口异常,事务回滚";
        }
        log.info("=================开始请求-订单微服务-placeOrder下订单接口Controller接口=================");
        return "请求成功";
    }

    /**
     * @Description: 调用其他服务测试spi
     *
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/27 下午5:40
     * @version:1.0.0
     */
    @GetMapping(value = "/testSpi")
    public String testSpi() {
        try {
            log.info("=================开始请求-订单微服务-testSpi调用其他服务测试spi的Controller接口=================");
            orderService.testSpi();
        } catch (Exception e) {
            e.printStackTrace();
            return "接口异常,事务回滚";
        }
        log.info("=================请求-订单微服务-testSpi调用其他服务测试spi的Controller接口完成=================");
        return "请求成功";
    }

}
